package com.team.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.team.mapper.AppInfoMapper;
import com.team.mapper.AppVersionMapper;
import com.team.pojo.AppInfo;
import com.team.pojo.AppInfoCondition;
import com.team.pojo.AppVersion;
import com.team.service.AppInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class AppInfoServiceImpl implements AppInfoService {
 @Autowired
 private AppInfoMapper appInfoMapper;
 @Autowired
 private AppVersionMapper appVersionMapper;
 @Override
 public PageInfo<AppInfo> getAppInfoCondition(AppInfoCondition appInfoCondition) {
   //开启分页
  PageHelper.startPage(appInfoCondition.getPage(),appInfoCondition.getPageSize());
  //查询记录
  List<AppInfo> list=appInfoMapper.searchAppInfo(appInfoCondition);
  return new PageInfo<>(list);
 }

 @Override
 public int addAppInfo(AppInfo appInfo) {

  return appInfoMapper.insertSelective(appInfo);
 }

 @Override
 public AppInfo getAppInfo(Long id) {
  return appInfoMapper.selectByPrimaryKey2(id);
 }

 @Override
 public int updateAppInfo(AppInfo appInfo) {
//有选择的修改列
  return appInfoMapper.updateByPrimaryKeySelective(appInfo);
 }

 @Override
 @Transactional   //修改，增加，删除或许会用到事务
 public void deleteAppInfo(Long appId) {
  //删除版本
  appVersionMapper.deleteVersionByAppId(appId);
  //删除App
  appInfoMapper.deleteByPrimaryKey(appId);
 }

 @Override
 public PageInfo<AppInfo> getNoPassAppInfo(AppInfoCondition appInfoCondition) {
  //开启分页
  PageHelper.startPage(appInfoCondition.getPage(),appInfoCondition.getPageSize());
  //调用持久化操作查询记录
  List<AppInfo> list=appInfoMapper.getNoPassAppInfo(appInfoCondition);
  //返回分页信息
  return new PageInfo<>(list);
 }

 @Override
 public AppInfo getCheckAppInfo(Long id) {
  return appInfoMapper.selectByPrimaryKey3(id);
 }

 @Override
 public int updateStatus(Long appid, Long status) {
  AppInfo appInfo=new AppInfo();
  appInfo.setId(appid);
  appInfo.setStatus(status);
  return appInfoMapper.updateByPrimaryKeySelective(appInfo);
 }
}
